package com.hangan.langchainspringstart.controller;

import com.hangan.langchainspringstart.service.MemoryStreamChat;
import com.hangan.langchainspringstart.service.StreamChat;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Flux;

/**
 * @author hang an
 * @since 2025/7/28
 */
@RestController
@RequiredArgsConstructor
@Slf4j
public class BasisAIController {

    private final StreamChat streamChat;
    private final MemoryStreamChat memoryStreamChat;

    @GetMapping(value = "/chat", produces = "text/html;charset=UTF-8")
    public Flux<String> streamChat(@RequestParam(value = "message") String message) {
        return streamChat.chat(message);
    }

    @GetMapping(value = "/memoryChat", produces = "text/html;charset=UTF-8")
    public Flux<String> memoryStreamChat(
            @RequestParam(value = "memoryId") String memoryId,
            @RequestParam(value = "message") String message) {
        return memoryStreamChat.chat(memoryId, message);
    }

    @GetMapping(value = "/stream", produces = MediaType.TEXT_EVENT_STREAM_VALUE)
    public Flux<String> stream(@RequestParam(value = "memoryId") String memoryId,
                               @RequestParam(value = "message") String message) {
        return memoryStreamChat.chat(memoryId, message);
    }


}
